﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Http;
using System.Net.Http.Headers;
using XclusiveClient.Classes;

namespace XclusiveClient
{
    public partial class ViewOrder : System.Web.UI.Page
    {
        protected void btnRetrieveById_Click(object sender, EventArgs e)
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("http://localhost:3676/");
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = client.GetAsync("api/order/" + tbxOrderID.Text).Result;
            if (response.IsSuccessStatusCode)
            {
                var o = response.Content.ReadAsAsync<Order>().Result;

                LblOrderID.Text = o.orderID.ToString();
                LblStatus.Text = o.status;
                LblDate.Text = o.ship_date;
                LblTime.Text = o.ship_time;
                LblType.Text = o.ship_type;
                LblAddress.Text = o.address;
                LblEmpID.Text = o.employeeID;
                LblListID.Text = o.listID.ToString();

                LblResult.Text = "Order retrieved!" + "<br/>";
            }
            else
            {                
                LblResult.Text = "Order could not be found. Error code: " + response.StatusCode + ", Reason:" + response.ReasonPhrase.ToString() + "<br/>";
            }
        }
    }
}